package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("travelCommend")
public class TravelCommendController {
    @Autowired
    private ITravelCommendService commendService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelCommendQueryObject qo, Model model){
        model.addAttribute("pageInfo",commendService.query(qo));
        return "/travelCommend/list";
    }

    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(TravelCommend commend, MultipartFile file){
        if (file != null && file.getSize() >0){
            String path = UploadUtil.upload(file, UploadUtil.PATH + "/upload");
            commend.setCoverUrl(path);
        }
        commendService.saveOrUpdate(commend);
        return "redirect:/travelCommend/list.do";
    }
}
